package com.spark.core.examples

import org.apache.spark.rdd.RDD
import org.apache.spark.util.LongAccumulator
import org.apache.spark.{SparkConf, SparkContext}

object AccumulatorTest {

  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setMaster("local")
    conf.setAppName("accumulator")
    val sc = new SparkContext(conf)
    sc.setLogLevel("error")

    val accumulator: LongAccumulator = sc.longAccumulator

    val lines: RDD[String] = sc.textFile("data/words", 4)
    println(lines.getNumPartitions)

    lines.map(line => {
      accumulator.add(1)
      println(line)
    }).count()

    println(accumulator.value)
  }

}
